﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain;
using MangoMes.Commont.DTOs.CommontFiles;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.Enterprises
{
    public class EnterpriseAddHandler : IRequestHandler<EnterpriseAddCommond, int>
    {
        private readonly IBateRepository<Enterprise> enterprisea;
        public EnterpriseAddHandler(IBateRepository<Enterprise> enterprisea)
        {
            this.enterprisea = enterprisea;
        }
        /// <summary>
        /// 新增企业管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(EnterpriseAddCommond request, CancellationToken cancellationToken)
        {
            DapperHelper helper = new DapperHelper();
            Enterprise enterprise=new Enterprise();
            enterprise.EnterpriseId = request.EnterpriseId;
            enterprise.EnterpriseName = request.EnterpriseName;
            enterprise.EnterpriseSname = request.EnterpriseSname;
            enterprise.EnterpriseUsci= request.EnterpriseUsci;
            enterprise.EnterprisePhone = request.EnterprisePhone;
            enterprise.EnterpriseLabel = request.EnterpriseLabel;
            enterprise.EnterpriseDescribe = request.EnterpriseDescribe;
            enterprise.EnterpriseHome = request.EnterpriseHome;
            string conn = helper.MangoMesWrite ;
            string str = $"insert into enterprisetable values (@enterpriseId,@enterpriseName,@enterpriseSname,@enterpriseLabel,@enterpriseHome,@enterprisePhone,@enterpriseUsci,@enterpriseDescribe)";
            var ai = await enterprisea.Add(str, enterprise, conn);
            return ai;
        }
    }
}
